<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./libs/vue3.js"></script>
    <style>
        .modal {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 500px;
            height: 300px;
            border: 10px solid rgba(0, 0, 0, 0.4);
            border-radius: 10px;
        }
    </style>
</head>

<body>
    <div id="app">
        <button @click="visible=!visible">toggle</button>
        <teleport to="body">
            <modal :visible="visible" />
        </teleport>
    </div>
</body>
<script>
    // 创建vue实例
    const app = Vue.createApp({
        data() {
            return {
                // 控制模态框组件的显示状态
                visible: false
            }
        }
    });
    // 注册一个模态框组件
    app.component('modal', {
        props: ['visible'],
        template: `
            <div class="modal" v-show="visible">
                
            </div>
        `
    });
    // 挂载vue实例
    app.mount('#app');
</script>

</html>